//
//  ChildBtn.m
//  iOSCodeLearning
//
//  Created by TFAppleWork-Summer on 2018/5/2.
//  Copyright © 2018年 Ace. All rights reserved.
//

#import "ChildBtn.h"

@implementation ChildBtn


-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
    if (self.btn) {
        // 判断当前点 在不在popBtn身上
        // 把当前点转换到btn身上
        CGPoint btnP = [self convertPoint:point toView:self.btn];
      
        if ([self.btn pointInside:btnP withEvent:event]) {
             return self.btn;
        }
        else{
            return [super hitTest:point withEvent:event];
        }
        
        
    }
    else{
        return [super hitTest:point withEvent:event];
    }
    
   
}


-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    // 1 获取UITouch对象
    UITouch *touch = [touches anyObject];
    // 2 获取当前手指的点， 上一个手指的点
    CGPoint curP = [touch locationInView:self];
    CGPoint preP = [touch previousLocationInView:self];
    // 3 计算偏移量
    CGFloat offsetX = curP.x -preP.x;
    CGFloat offsetY = curP.y - preP.y;
    // 4 平移
    self.transform = CGAffineTransformTranslate(self.transform, offsetX, offsetY);
}

@end
